﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Inspinia_MVC5.Models;
using Inspinia_MVC5.Data;
using Webdiyer.WebControls.Mvc;
using System.Net;

namespace Inspinia_MVC5.Controllers
{
    public class UserController : Controller
    {
        private BooksSystemContext db = new BooksSystemContext();

        // GET: User
        public ActionResult Index()
        {

            return View();
        }
        public ActionResult EbookList(int id = 1)
        {
            var model = db.Ebooks.OrderByDescending(a => a.Id).ToPagedList(id, 2);
            if (Request.IsAjaxRequest())
                return PartialView("_EbookLi", model);
            return View(model);

        }
        public ActionResult EbookDetail(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Ebook ebook = db.Ebooks.Find(id);
            if (ebook == null)
            {
                return HttpNotFound();
            }
            
            return View(ebook);
        }
        public ActionResult EbookView(int ?id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Ebook ebook = db.Ebooks.Find(id);
            if (ebook == null)
            {
                return HttpNotFound();
            }

            ViewBag.path = "/pdf/" + ebook.EbookPath;
            //ViewBag.path = "H:/0Project/Book/ASPNET_MVC5_Full_Version/Inspinia_MVC5/pdf/87652254105201.pdf";

            //ViewBag.path = Server.MapPath("/pdf") +"/"+ ebook.EbookPath;

            return View(ebook);
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}